package arkanoid.components;

import java.awt.Color;

import arkanoid.scenes.Level;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Rectangle;
import com.uqbar.vainilla.events.constants.Key;

public class Palette extends GameComponent<Level> {
	
	private int width;
	private int height;
	
	public Palette() {
		this.changeSize(60, 10);
	}
	
	@Override
	public void update(DeltaState deltaState) {
		if(deltaState.isKeyBeingHold(Key.LEFT) && this.getX() > 0) {
			this.move(-0.3, 0);
		}
		if(deltaState.isKeyBeingHold(Key.RIGHT) && this.getX() < this.getGame().getDisplayWidth() - getWidth()) {
			this.move(0.3, 0);
		}
	}
	
	public void changeSize(int width, int height) {
		this.setWidth(width);
		this.setHeight(height);
		this.setAppearance(new Rectangle(Color.getHSBColor(0.15f, 0.8f, 0.55f), this.getWidth(), this.getHeight()));
	}
	
	public void onSceneActivated() {
		this.setX(this.getGame().getDisplayWidth() / 2);
		this.setY(this.getGame().getDisplayHeight() * 92 / 100);
	}
	
	

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

}
